<?php
//商品品牌管理模型
class GoodsBrandModel extends Model{
         public $table="brand";
         public $validate=array(
               array("bname","nonull","品牌名称为空",2,3)
         	);
         //插入数据
         public function addBrand(){
         	 if($this->create()){
                 $state=$this->add();
                  if($state){
                     if($this->updateBrand()){
                     	return true;
                     }
                  }
         	 }else{
         	 	return false;
         	 }
         }
         //删除数据
         public function delBrand(){
         	   if(M("brand")->where(array("bid"=>Q("bid")))->del()){
         	   	if($this->updateBrand()){
         	   		return true;
         	   	}
         	   }else{
                     $this->error="删除失败";
                     return false;
         	   }
         }
         //编辑数据
         public function editBrand(){
         	   if($this->create()){
         	   	if($this->save()){
         	   		return true;
         	   	}
         	   }else{
         	   	return false;
         	   }
         }
         //更新缓存
         public function updateBrand(){
         	   $brand=M("brand")->getField("bid,bname");
         	   if(cache("brand",$brand)){
         	   	return true;
         	   }
         }

}